Socket
Socket
Sign inDemoInstall

image-type

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-type

Detect the image type of a Buffer/Uint8Array


Version published
Weekly downloads
55K
decreased by-16.42%
Maintainers
1
Weekly downloads
 
Created
Source

image-type Build Status

Detect the image type of a Buffer/Uint8Array

See the file-type module for more file types.

Install

$ npm install --save image-type
$ bower install --save image-type
$ component install sindresorhus/image-type

Usage

Node.js
var readChunk = require('read-chunk'); // npm install read-chunk
var imageType = require('image-type');
var buffer = readChunk.sync('unicorn.png', 0, 12);

imageType(buffer);
//=> png
Browser
var xhr = new XMLHttpRequest();
xhr.open('GET', 'unicorn.png');
xhr.responseType = 'arraybuffer';

xhr.onload = function () {
	imageType(new Uint8Array(this.response));
	//=> png
};

xhr.send();

API

imageType(buffer)

Returns: png, jpg, gif, webp, tif, bmp, jxr, psd, false

SVG isn't included as it requires the whole file to be read, but you can get it here.

buffer

Type: buffer (Node.js), uint8array

It only needs the first 12 bytes.

CLI

$ npm install --global image-type
$ image-type --help

Usage
  $ cat <filename> | image-type
  $ image-type <filename>

Example
  $ cat unicorn.png | image-type
  png

License

MIT © Sindre Sorhus

Keywords

FAQs

Package last updated on 30 Apr 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc